import os
from pathlib import Path

__all__ = {
    'DATABASES'
}

base_folder = Path(__file__).resolve().parent.parent

# 本地测试环境 db.sqlite
LOCAL_DATABASE = {
    'ENGINE': 'django.db.backends.sqlite3',
    'NAME': os.path.join(base_folder, 'db.sqlite3'),
}

# 开发环境
MYSQL_DATABASE = {
    'ENGINE': 'django.db.backends.mysql',
    'NAME': os.environ.get('MYSQL_DATABASE', ''),
    'USER': os.environ.get('MYSQL_USER', ''),
    'PASSWORD': os.environ.get('MYSQL_PASSWORD', ''),
    'HOST': os.environ.get('MYSQL_HOST', ''),
    'PORT': os.environ.get('MYSQL_PORT', ''),
}

MAIN_DATABASE = None
if os.environ.get('ENV', 'local') == 'local':
    MAIN_DATABASE = LOCAL_DATABASE
else:
    MAIN_DATABASE = MYSQL_DATABASE

# Database
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases

DATABASES = {
    'default': MAIN_DATABASE
}
